package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.StockQo;
import com.qf.staff.common.vo.StockVo;
import com.qf.staff.service.StockService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "库存管理Api")
@RestController
@RequestMapping("/stock")
public class StockController {
    @Resource
    StockService stockService;

    @ApiOperation("查询所有库存信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<StockVo>> list(@RequestParam(defaultValue = "1") int page,
                                           @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(stockService.list(page, size));
    }

    @ApiOperation("根据status删除库存信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "stockId", value = "库存ID")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove")
    public RespResult<Integer> remove(StockQo stockQo) {
        return RespResult.success(stockService.delete(stockQo));
    }

    @ApiOperation("根据ID修改库存信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stockId", value = "库存ID"),
            @ApiImplicitParam(name = "stockTime", value = "入库时间"),
            @ApiImplicitParam(name = "stockMoney", value = "入库金额"),
            @ApiImplicitParam(name = "stockName", value = "入库名称"),
            @ApiImplicitParam(name = "stockNumber", value = "入库数量")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(StockQo stockQo) {
        return RespResult.success(stockService.modify(stockQo));
    }

    @ApiOperation("添加库存信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stockId", value = "库存ID"),
            @ApiImplicitParam(name = "stockTime", value = "入库时间"),
            @ApiImplicitParam(name = "stockMoney", value = "入库金额"),
            @ApiImplicitParam(name = "stockName", value = "入库名称"),
            @ApiImplicitParam(name = "stockNumber", value = "入库数量")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(StockQo stockQo) {
        return RespResult.success(stockService.add(stockQo));
    }
}
